package edu.hbsi.demo4;


public class San {
    private int x, y, z;

    public San(int a, int b, int c) {
        this.x = a;
        this.y = b;
        this.z = c;
    }

    public double getArea() throws NotSanjiaoException {
        if (x + y <= z || x + z <= y || y + z <= x) {
            throw new NotSanjiaoException("三边无法构成三角形");
        }
        // 使用海伦公式计算面积
        double s = (x + y + z) / 2.0;
        return Math.sqrt(s * (s - x) * (s - y) * (s - z));
    }

    public void showInfo() throws NotSanjiaoException {
        if (x + y <= z || x + z <= y || y + z <= x) {
            throw new NotSanjiaoException("三边无法构成三角形");
        }
        System.out.println("三角形三边长为: " + x + ", " + y + ", " + z);
    }
}
